/*
 * Selling Partner API for Replenishment
 * The Selling Partner API for Replenishment (Replenishment API) provides programmatic access to replenishment program metrics and offers. These programs provide recurring delivery of any replenishable item at a frequency chosen by the customer.  The Replenishment API is available worldwide wherever Amazon Subscribe & Save is available or is supported. The API is available to vendors and FBA selling partners.
 *
 * OpenAPI spec version: 2022-11-07
 *
 *
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen.git
 * Do not edit the class manually.
 */

package software.amazon.spapi.api.replenishment.v2022_11_07;

import com.amazon.SellingPartnerAPIAA.LWAAccessTokenCache;
import com.amazon.SellingPartnerAPIAA.LWAAccessTokenCacheImpl;
import com.amazon.SellingPartnerAPIAA.LWAAuthorizationCredentials;
import com.amazon.SellingPartnerAPIAA.LWAAuthorizationSigner;
import com.amazon.SellingPartnerAPIAA.LWAException;
import com.amazon.SellingPartnerAPIAA.RestrictedDataTokenSigner;
import com.google.gson.reflect.TypeToken;
import io.github.bucket4j.Bucket;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import software.amazon.spapi.ApiCallback;
import software.amazon.spapi.ApiClient;
import software.amazon.spapi.ApiException;
import software.amazon.spapi.ApiResponse;
import software.amazon.spapi.Configuration;
import software.amazon.spapi.Pair;
import software.amazon.spapi.ProgressRequestBody;
import software.amazon.spapi.StringUtil;
import software.amazon.spapi.models.replenishment.v2022_11_07.ListOfferMetricsRequest;
import software.amazon.spapi.models.replenishment.v2022_11_07.ListOfferMetricsResponse;
import software.amazon.spapi.models.replenishment.v2022_11_07.ListOffersRequest;
import software.amazon.spapi.models.replenishment.v2022_11_07.ListOffersResponse;

public class OffersApi {
    private ApiClient apiClient;
    private Boolean disableRateLimiting;

    public OffersApi(ApiClient apiClient, Boolean disableRateLimiting) {
        this.apiClient = apiClient;
        this.disableRateLimiting = disableRateLimiting;
    }

    private final Configuration config = Configuration.get();

    public final Bucket listOfferMetricsBucket = Bucket.builder()
            .addLimit(config.getLimit("OffersApi-listOfferMetrics"))
            .build();

    public final Bucket listOffersBucket =
            Bucket.builder().addLimit(config.getLimit("OffersApi-listOffers")).build();

    /**
     * Build call for listOfferMetrics
     *
     * @param body The request body for the &#x60;listOfferMetrics&#x60; operation. (optional)
     * @param progressRequestListener Progress request listener
     * @return Call to execute
     * @throws ApiException If fail to serialize the request body object
     * @throws LWAException If calls to fetch LWA access token fails
     */
    private okhttp3.Call listOfferMetricsCall(
            ListOfferMetricsRequest body, final ProgressRequestBody.ProgressRequestListener progressRequestListener)
            throws ApiException, LWAException {
        Object localVarPostBody = body;

        // create path and map variables
        String localVarPath = "/replenishment/2022-11-07/offers/metrics/search";

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();

        Map<String, Object> localVarFormParams = new HashMap<String, Object>();

        final String[] localVarAccepts = {"application/json"};
        final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
        if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);

        final String[] localVarContentTypes = {"application/json"};
        final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
        localVarHeaderParams.put("Content-Type", localVarContentType);

        return apiClient.buildCall(
                localVarPath,
                "POST",
                localVarQueryParams,
                localVarCollectionQueryParams,
                localVarPostBody,
                localVarHeaderParams,
                localVarFormParams,
                progressRequestListener);
    }

    private okhttp3.Call listOfferMetricsValidateBeforeCall(
            ListOfferMetricsRequest body, final ProgressRequestBody.ProgressRequestListener progressRequestListener)
            throws ApiException, LWAException {

        return listOfferMetricsCall(body, progressRequestListener);
    }

    /**
     * Returns aggregated replenishment program metrics for a selling partner&#x27;s offers. **Usage Plan:** | Rate
     * (requests per second) | Burst | | ---- | ---- | | 1 | 1 | The &#x60;x-amzn-RateLimit-Limit&#x60; response header
     * returns the usage plan rate limits that were applied to the requested operation, when available. The table above
     * indicates the default rate and burst values for this operation. Selling partners whose business demands require
     * higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage
     * Plans and Rate Limits in the Selling Partner
     * API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
     *
     * @param body The request body for the &#x60;listOfferMetrics&#x60; operation. (optional)
     * @param restrictedDataToken Restricted Data Token (optional)
     * @return ListOfferMetricsResponse
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @throws LWAException If calls to fetch LWA access token fails
     */
    public ListOfferMetricsResponse listOfferMetrics(ListOfferMetricsRequest body, String restrictedDataToken)
            throws ApiException, LWAException {
        ApiResponse<ListOfferMetricsResponse> resp = listOfferMetricsWithHttpInfo(body, restrictedDataToken);
        return resp.getData();
    }

    /**
     * Returns aggregated replenishment program metrics for a selling partner&#x27;s offers. **Usage Plan:** | Rate
     * (requests per second) | Burst | | ---- | ---- | | 1 | 1 | The &#x60;x-amzn-RateLimit-Limit&#x60; response header
     * returns the usage plan rate limits that were applied to the requested operation, when available. The table above
     * indicates the default rate and burst values for this operation. Selling partners whose business demands require
     * higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage
     * Plans and Rate Limits in the Selling Partner
     * API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
     *
     * @param body The request body for the &#x60;listOfferMetrics&#x60; operation. (optional)
     * @return ListOfferMetricsResponse
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @throws LWAException If calls to fetch LWA access token fails
     */
    public ListOfferMetricsResponse listOfferMetrics(ListOfferMetricsRequest body) throws ApiException, LWAException {
        ApiResponse<ListOfferMetricsResponse> resp = listOfferMetricsWithHttpInfo(body, null);
        return resp.getData();
    }

    /**
     * Returns aggregated replenishment program metrics for a selling partner&#x27;s offers. **Usage Plan:** | Rate
     * (requests per second) | Burst | | ---- | ---- | | 1 | 1 | The &#x60;x-amzn-RateLimit-Limit&#x60; response header
     * returns the usage plan rate limits that were applied to the requested operation, when available. The table above
     * indicates the default rate and burst values for this operation. Selling partners whose business demands require
     * higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage
     * Plans and Rate Limits in the Selling Partner
     * API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
     *
     * @param body The request body for the &#x60;listOfferMetrics&#x60; operation. (optional)
     * @param restrictedDataToken Restricted Data Token (optional)
     * @return ApiResponse&lt;ListOfferMetricsResponse&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @throws LWAException If calls to fetch LWA access token fails
     */
    public ApiResponse<ListOfferMetricsResponse> listOfferMetricsWithHttpInfo(
            ListOfferMetricsRequest body, String restrictedDataToken) throws ApiException, LWAException {
        okhttp3.Call call = listOfferMetricsValidateBeforeCall(body, null);

        if (restrictedDataToken != null) {
            okhttp3.Request request = call.request();
            request = RestrictedDataTokenSigner.sign(request, restrictedDataToken, "OffersApi-listOfferMetrics");
            call = apiClient.getHttpClient().newCall(request);
        }

        if (disableRateLimiting || listOfferMetricsBucket.tryConsume(1)) {
            Type localVarReturnType = new TypeToken<ListOfferMetricsResponse>() {}.getType();
            return apiClient.execute(call, localVarReturnType);
        } else throw new ApiException.RateLimitExceeded("listOfferMetrics operation exceeds rate limit");
    }

    /**
     * Returns aggregated replenishment program metrics for a selling partner&#x27;s offers. **Usage Plan:** | Rate
     * (requests per second) | Burst | | ---- | ---- | | 1 | 1 | The &#x60;x-amzn-RateLimit-Limit&#x60; response header
     * returns the usage plan rate limits that were applied to the requested operation, when available. The table above
     * indicates the default rate and burst values for this operation. Selling partners whose business demands require
     * higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage
     * Plans and Rate Limits in the Selling Partner
     * API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
     *
     * @param body The request body for the &#x60;listOfferMetrics&#x60; operation. (optional)
     * @return ApiResponse&lt;ListOfferMetricsResponse&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @throws LWAException If calls to fetch LWA access token fails
     */
    public ApiResponse<ListOfferMetricsResponse> listOfferMetricsWithHttpInfo(ListOfferMetricsRequest body)
            throws ApiException, LWAException {
        return listOfferMetricsWithHttpInfo(body, null);
    }

    /**
     * (asynchronously) Returns aggregated replenishment program metrics for a selling partner&#x27;s offers. **Usage
     * Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 1 | The &#x60;x-amzn-RateLimit-Limit&#x60;
     * response header returns the usage plan rate limits that were applied to the requested operation, when available.
     * The table above indicates the default rate and burst values for this operation. Selling partners whose business
     * demands require higher throughput may see higher rate and burst values than those shown here. For more
     * information, see [Usage Plans and Rate Limits in the Selling Partner
     * API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
     *
     * @param body The request body for the &#x60;listOfferMetrics&#x60; operation. (optional)
     * @param callback The callback to be executed when the API call finishes
     * @return The request call
     * @throws ApiException If fail to process the API call, e.g. serializing the request body object
     * @throws LWAException If calls to fetch LWA access token fails
     */
    public okhttp3.Call listOfferMetricsAsync(
            ListOfferMetricsRequest body, final ApiCallback<ListOfferMetricsResponse> callback)
            throws ApiException, LWAException {
        return listOfferMetricsAsync(body, callback, null);
    }
    /**
     * (asynchronously) Returns aggregated replenishment program metrics for a selling partner&#x27;s offers. **Usage
     * Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 1 | The &#x60;x-amzn-RateLimit-Limit&#x60;
     * response header returns the usage plan rate limits that were applied to the requested operation, when available.
     * The table above indicates the default rate and burst values for this operation. Selling partners whose business
     * demands require higher throughput may see higher rate and burst values than those shown here. For more
     * information, see [Usage Plans and Rate Limits in the Selling Partner
     * API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
     *
     * @param body The request body for the &#x60;listOfferMetrics&#x60; operation. (optional)
     * @param callback The callback to be executed when the API call finishes
     * @param restrictedDataToken Restricted Data Token (optional)
     * @return The request call
     * @throws ApiException If fail to process the API call, e.g. serializing the request body object
     * @throws LWAException If calls to fetch LWA access token fails
     */
    public okhttp3.Call listOfferMetricsAsync(
            ListOfferMetricsRequest body,
            final ApiCallback<ListOfferMetricsResponse> callback,
            String restrictedDataToken)
            throws ApiException, LWAException {

        ProgressRequestBody.ProgressRequestListener progressRequestListener = null;

        if (callback != null) {
            progressRequestListener = callback::onUploadProgress;
        }

        okhttp3.Call call = listOfferMetricsValidateBeforeCall(body, progressRequestListener);

        if (restrictedDataToken != null) {
            okhttp3.Request request = call.request();
            request = RestrictedDataTokenSigner.sign(request, restrictedDataToken, "OffersApi-listOfferMetrics");
            call = apiClient.getHttpClient().newCall(request);
        }

        if (disableRateLimiting || listOfferMetricsBucket.tryConsume(1)) {
            Type localVarReturnType = new TypeToken<ListOfferMetricsResponse>() {}.getType();
            apiClient.executeAsync(call, localVarReturnType, callback);
            return call;
        } else throw new ApiException.RateLimitExceeded("listOfferMetrics operation exceeds rate limit");
    }
    /**
     * Build call for listOffers
     *
     * @param body The request body for the &#x60;listOffers&#x60; operation. (optional)
     * @param progressRequestListener Progress request listener
     * @return Call to execute
     * @throws ApiException If fail to serialize the request body object
     * @throws LWAException If calls to fetch LWA access token fails
     */
    private okhttp3.Call listOffersCall(
            ListOffersRequest body, final ProgressRequestBody.ProgressRequestListener progressRequestListener)
            throws ApiException, LWAException {
        Object localVarPostBody = body;

        // create path and map variables
        String localVarPath = "/replenishment/2022-11-07/offers/search";

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();

        Map<String, Object> localVarFormParams = new HashMap<String, Object>();

        final String[] localVarAccepts = {"application/json"};
        final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
        if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);

        final String[] localVarContentTypes = {"application/json"};
        final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
        localVarHeaderParams.put("Content-Type", localVarContentType);

        return apiClient.buildCall(
                localVarPath,
                "POST",
                localVarQueryParams,
                localVarCollectionQueryParams,
                localVarPostBody,
                localVarHeaderParams,
                localVarFormParams,
                progressRequestListener);
    }

    private okhttp3.Call listOffersValidateBeforeCall(
            ListOffersRequest body, final ProgressRequestBody.ProgressRequestListener progressRequestListener)
            throws ApiException, LWAException {

        return listOffersCall(body, progressRequestListener);
    }

    /**
     * Returns the details of a selling partner&#x27;s replenishment program offers. **Usage Plan:** | Rate (requests
     * per second) | Burst | | ---- | ---- | | 1 | 1 | The &#x60;x-amzn-RateLimit-Limit&#x60; response header returns
     * the usage plan rate limits that were applied to the requested operation, when available. The table above
     * indicates the default rate and burst values for this operation. Selling partners whose business demands require
     * higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage
     * Plans and Rate Limits in the Selling Partner
     * API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
     *
     * @param body The request body for the &#x60;listOffers&#x60; operation. (optional)
     * @param restrictedDataToken Restricted Data Token (optional)
     * @return ListOffersResponse
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @throws LWAException If calls to fetch LWA access token fails
     */
    public ListOffersResponse listOffers(ListOffersRequest body, String restrictedDataToken)
            throws ApiException, LWAException {
        ApiResponse<ListOffersResponse> resp = listOffersWithHttpInfo(body, restrictedDataToken);
        return resp.getData();
    }

    /**
     * Returns the details of a selling partner&#x27;s replenishment program offers. **Usage Plan:** | Rate (requests
     * per second) | Burst | | ---- | ---- | | 1 | 1 | The &#x60;x-amzn-RateLimit-Limit&#x60; response header returns
     * the usage plan rate limits that were applied to the requested operation, when available. The table above
     * indicates the default rate and burst values for this operation. Selling partners whose business demands require
     * higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage
     * Plans and Rate Limits in the Selling Partner
     * API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
     *
     * @param body The request body for the &#x60;listOffers&#x60; operation. (optional)
     * @return ListOffersResponse
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @throws LWAException If calls to fetch LWA access token fails
     */
    public ListOffersResponse listOffers(ListOffersRequest body) throws ApiException, LWAException {
        ApiResponse<ListOffersResponse> resp = listOffersWithHttpInfo(body, null);
        return resp.getData();
    }

    /**
     * Returns the details of a selling partner&#x27;s replenishment program offers. **Usage Plan:** | Rate (requests
     * per second) | Burst | | ---- | ---- | | 1 | 1 | The &#x60;x-amzn-RateLimit-Limit&#x60; response header returns
     * the usage plan rate limits that were applied to the requested operation, when available. The table above
     * indicates the default rate and burst values for this operation. Selling partners whose business demands require
     * higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage
     * Plans and Rate Limits in the Selling Partner
     * API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
     *
     * @param body The request body for the &#x60;listOffers&#x60; operation. (optional)
     * @param restrictedDataToken Restricted Data Token (optional)
     * @return ApiResponse&lt;ListOffersResponse&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @throws LWAException If calls to fetch LWA access token fails
     */
    public ApiResponse<ListOffersResponse> listOffersWithHttpInfo(ListOffersRequest body, String restrictedDataToken)
            throws ApiException, LWAException {
        okhttp3.Call call = listOffersValidateBeforeCall(body, null);

        if (restrictedDataToken != null) {
            okhttp3.Request request = call.request();
            request = RestrictedDataTokenSigner.sign(request, restrictedDataToken, "OffersApi-listOffers");
            call = apiClient.getHttpClient().newCall(request);
        }

        if (disableRateLimiting || listOffersBucket.tryConsume(1)) {
            Type localVarReturnType = new TypeToken<ListOffersResponse>() {}.getType();
            return apiClient.execute(call, localVarReturnType);
        } else throw new ApiException.RateLimitExceeded("listOffers operation exceeds rate limit");
    }

    /**
     * Returns the details of a selling partner&#x27;s replenishment program offers. **Usage Plan:** | Rate (requests
     * per second) | Burst | | ---- | ---- | | 1 | 1 | The &#x60;x-amzn-RateLimit-Limit&#x60; response header returns
     * the usage plan rate limits that were applied to the requested operation, when available. The table above
     * indicates the default rate and burst values for this operation. Selling partners whose business demands require
     * higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage
     * Plans and Rate Limits in the Selling Partner
     * API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
     *
     * @param body The request body for the &#x60;listOffers&#x60; operation. (optional)
     * @return ApiResponse&lt;ListOffersResponse&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @throws LWAException If calls to fetch LWA access token fails
     */
    public ApiResponse<ListOffersResponse> listOffersWithHttpInfo(ListOffersRequest body)
            throws ApiException, LWAException {
        return listOffersWithHttpInfo(body, null);
    }

    /**
     * (asynchronously) Returns the details of a selling partner&#x27;s replenishment program offers. **Usage Plan:** |
     * Rate (requests per second) | Burst | | ---- | ---- | | 1 | 1 | The &#x60;x-amzn-RateLimit-Limit&#x60; response
     * header returns the usage plan rate limits that were applied to the requested operation, when available. The table
     * above indicates the default rate and burst values for this operation. Selling partners whose business demands
     * require higher throughput may see higher rate and burst values than those shown here. For more information, see
     * [Usage Plans and Rate Limits in the Selling Partner
     * API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
     *
     * @param body The request body for the &#x60;listOffers&#x60; operation. (optional)
     * @param callback The callback to be executed when the API call finishes
     * @return The request call
     * @throws ApiException If fail to process the API call, e.g. serializing the request body object
     * @throws LWAException If calls to fetch LWA access token fails
     */
    public okhttp3.Call listOffersAsync(ListOffersRequest body, final ApiCallback<ListOffersResponse> callback)
            throws ApiException, LWAException {
        return listOffersAsync(body, callback, null);
    }
    /**
     * (asynchronously) Returns the details of a selling partner&#x27;s replenishment program offers. **Usage Plan:** |
     * Rate (requests per second) | Burst | | ---- | ---- | | 1 | 1 | The &#x60;x-amzn-RateLimit-Limit&#x60; response
     * header returns the usage plan rate limits that were applied to the requested operation, when available. The table
     * above indicates the default rate and burst values for this operation. Selling partners whose business demands
     * require higher throughput may see higher rate and burst values than those shown here. For more information, see
     * [Usage Plans and Rate Limits in the Selling Partner
     * API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
     *
     * @param body The request body for the &#x60;listOffers&#x60; operation. (optional)
     * @param callback The callback to be executed when the API call finishes
     * @param restrictedDataToken Restricted Data Token (optional)
     * @return The request call
     * @throws ApiException If fail to process the API call, e.g. serializing the request body object
     * @throws LWAException If calls to fetch LWA access token fails
     */
    public okhttp3.Call listOffersAsync(
            ListOffersRequest body, final ApiCallback<ListOffersResponse> callback, String restrictedDataToken)
            throws ApiException, LWAException {

        ProgressRequestBody.ProgressRequestListener progressRequestListener = null;

        if (callback != null) {
            progressRequestListener = callback::onUploadProgress;
        }

        okhttp3.Call call = listOffersValidateBeforeCall(body, progressRequestListener);

        if (restrictedDataToken != null) {
            okhttp3.Request request = call.request();
            request = RestrictedDataTokenSigner.sign(request, restrictedDataToken, "OffersApi-listOffers");
            call = apiClient.getHttpClient().newCall(request);
        }

        if (disableRateLimiting || listOffersBucket.tryConsume(1)) {
            Type localVarReturnType = new TypeToken<ListOffersResponse>() {}.getType();
            apiClient.executeAsync(call, localVarReturnType, callback);
            return call;
        } else throw new ApiException.RateLimitExceeded("listOffers operation exceeds rate limit");
    }

    public static class Builder {
        private LWAAuthorizationCredentials lwaAuthorizationCredentials;
        private String endpoint;
        private LWAAccessTokenCache lwaAccessTokenCache;
        private Boolean disableAccessTokenCache = false;
        private Boolean disableRateLimiting = false;

        public Builder lwaAuthorizationCredentials(LWAAuthorizationCredentials lwaAuthorizationCredentials) {
            this.lwaAuthorizationCredentials = lwaAuthorizationCredentials;
            return this;
        }

        public Builder endpoint(String endpoint) {
            this.endpoint = endpoint;
            return this;
        }

        public Builder lwaAccessTokenCache(LWAAccessTokenCache lwaAccessTokenCache) {
            this.lwaAccessTokenCache = lwaAccessTokenCache;
            return this;
        }

        public Builder disableAccessTokenCache() {
            this.disableAccessTokenCache = true;
            return this;
        }

        public Builder disableRateLimiting() {
            this.disableRateLimiting = true;
            return this;
        }

        public OffersApi build() {
            if (lwaAuthorizationCredentials == null) {
                throw new RuntimeException("LWAAuthorizationCredentials not set");
            }

            if (StringUtil.isEmpty(endpoint)) {
                throw new RuntimeException("Endpoint not set");
            }

            LWAAuthorizationSigner lwaAuthorizationSigner = null;
            if (disableAccessTokenCache) {
                lwaAuthorizationSigner = new LWAAuthorizationSigner(lwaAuthorizationCredentials);
            } else {
                if (lwaAccessTokenCache == null) {
                    lwaAccessTokenCache = new LWAAccessTokenCacheImpl();
                }
                lwaAuthorizationSigner = new LWAAuthorizationSigner(lwaAuthorizationCredentials, lwaAccessTokenCache);
            }

            return new OffersApi(
                    new ApiClient()
                            .setLWAAuthorizationSigner(lwaAuthorizationSigner)
                            .setBasePath(endpoint),
                    disableRateLimiting);
        }
    }
}
